package mutilthread;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: volatile 关键字
 * User: Li_yizYa
 * Date: 2025—03—24
 * Time: 17:39
 */
public class Demo8 {
    private static volatile int n = 0;
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
           while (n == 0) {
               //啥都不写
           }
            System.out.println("t1 线程结束循环");
        });

        Thread t2 = new Thread(() -> {
           Scanner scan = new Scanner(System.in);
            System.out.println("请输入一个整数：");
            n = scan.nextInt();
        });

        t1.start();
        t2.start();
    }
}
